//
//  YFNetError.m
//  CoollangTennisBall
//
//  Created by Coollang on 2018/1/12.
//  Copyright © 2018年 Coollang-YF. All rights reserved.
//

#import "YFNetError.h"

@implementation YFNetError
+ (NSError *)creatErrorWithRet:(WebRespondType)ret {
    NSError *error;
    switch (ret) {
        default:// 未知错误
            error = [YFNetError errorWithDomain:@"Unknown Mistake" code:WebRespondTypeOther];
            break;
    }
     return error;
}

+ (WebRespondType)WebRespondTypeWithRet:(NSString *)retStr {
    if (retStr.length <= 0) {
        return WebRespondTypeOther;
    }
    NSInteger ret = [retStr integerValue];
    return ret;
}
@end

@implementation NSError (MessageUtils)

+ (NSError *)errorWithDomain:(NSString *)aDomain code:(NSInteger)aCode {
    return [NSError errorWithDomain:aDomain code:aCode userInfo:nil];
}

+ (NSError *)errorWithDomain:(NSString *)aDomain
                        code:(NSInteger)aCode
        localizedDescription:(NSString *)aDescription {
    NSDictionary *userInfo = nil;
    
    if (aDescription) {
        userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
                    aDescription,
                    NSLocalizedDescriptionKey, nil];
    }
    return [NSError errorWithDomain:aDomain code:aCode userInfo:userInfo];
}

- (NSString *)errorMessage {
    NSString *userFriendlyMessage = @"";
    if ([self isKindOfClass:[YFNetError class]]) {
        userFriendlyMessage = self.domain;
    }else {
        userFriendlyMessage = self.localizedDescription;
    }
    return userFriendlyMessage;
}


@end


